<?php
/* This file is part of Mirasol CMS
   (C) 2009, 2011 by Chris Alban Hansen.
   Released under the terms of the GNU General Public License.
   See COPYING in the top level directory of the Mirasol CMS installation. */

if (!defined ("_READCONF_PHP_"))
{
  define ("_READCONF_PHP_", "1");
  
  function readsiteconf ($section)
  {
    $xmlres = xml_parser_create ("utf-8");
    
    /* Read the config file */
    $xmldata = file_get_contents ("{$_SERVER['DOCUMENT_ROOT']}/includes/site.conf");

    /* Parse the config file and add it to $values struct */
    xml_parse_into_struct ($xmlres, $xmldata, $values);

    xml_parser_free ($xmlres);
    
    /* Save the requested settings */
    $setting = array ();
    $i = 0;
    while ($values[$i])
      {
        /* Ignore the site.config tag */
        if (strcasecmp ($values[$i]['tag'], "site.config"))
          {
            /* So, we found our section */
            if (strcasecmp ($values[$i]['tag'], $section) == 0 && $values[$i]['type'] == "open")
              {
                /* Extract all tags and values */
                while ($values[$i])
                  {
                    /* End loop if the end tag of the section is found */
                    if (strcasecmp ($values[$i]['tag'], $section) == 0 && $values[$i]['type'] == "close")
                      break;
                
                    /* Omit tags with the requested section name */
                    if (strcasecmp ($values[$i]['tag'], $section))
                      $setting[strtolower ($values[$i]['tag'])] = $values[$i]['value'];
              
                    $i++;
                  }
                
                /* Done, let's get out of this loop */
                break;
             }
          }
        $i++;
    }
    return $setting;
  }
}
?>
